const Service = require('egg').Service;

const sequelizeUtil = require('../lib/sequelizeUtil')

class AppService extends Service {

    async page(query) {
        const { app: { model: { Projet, ProjetProduct, ProjectCost } } } = this

        sequelizeUtil.parsePageParam(query)

        const ret = Project.findAndCountAll({
            limit: query.limit,
            offset: query.offset,
            order: query.order,
            where: query.where,
            include: [
                { model: ProjectCost },
                { model: ProjetProduct }
            ]
        })
    }

    async remove(id) {
        const { app: { model: { Projet, ProjetProduct, ProjectCost } } } = app
        Projet.destory({
            where: {
                id
            }
        })
        ProjetProduct.destory({
            where: {
                proj_id: id
            }
        })
        ProjectCost.destory({
            where: {
                proj_id: id
            }
        })
    }

}

module.exports = AppService